package com.teach.service.impl;

import com.teach.dao.MedalInfoDAO;
import com.teach.dao.impl.MedalInfoDAOImpl;
import com.teach.dto.MedalDto;
import com.teach.dto.MedalSearch;
import com.teach.dto.PageDTO;
import com.teach.service.MedalService;

import java.util.List;

/**
 * <pre>
 * -
 * Author : J.L.Zhou
 * E-Mail : 2233875735@qq.com
 * Tel : 151 1104 7708
 * Date : 2022-05-12 10:23
 * Version : 1.0
 * Copyright 2022 jlzhou.top Inc. All rights reserved.
 * Warning: this content is only for internal circulation of the company.
 *          It is forbidden to divulge it or use it for other commercial purposes.
 * </pre>
 **/
public class MedalServiceImpl implements MedalService {

  private MedalInfoDAO dao = new MedalInfoDAOImpl();

  @Override
  public List<MedalDto> list(MedalSearch search) {
    try{
      return dao.selectSearch(search);
    }catch (Exception e){
      throw new RuntimeException("获取奖牌列表失败",e);
    }
  }

  @Override
  public PageDTO<MedalDto> page(MedalSearch search) {
    try {
      PageDTO<MedalDto> p = new PageDTO<>(dao.countSearch(search), search.getCurrent(), search.getRowMax());
      search.setCurrent(p.getCurrent());
      p.setList(dao.selectSearch(search));
      return p;
    }catch (Exception e){
      throw new RuntimeException("获取奖牌分页失败",e);
    }
  }
}
